<template>
  <el-form :model="loginForm" class="login-container">
    <h3>系统登录</h3>
    <el-form-item>
      <el-input
        type="input"
        placeholder="请输入账号"
        v-model="loginForm.username"
      ></el-input>
    </el-form-item>
    <el-form-item>
      <el-input
        type="password"
        placeholder="请输入密码"
        v-model="loginForm.password"
      ></el-input>
    </el-form-item>
    <el-button type="primary" @click="login">登录</el-button>
  </el-form>
</template>
<script setup>
import { reactive, getCurrentInstance } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import permission from '../api/permission'
const { proxy } = getCurrentInstance()
const loginForm = reactive({
  username: 'admin',
  password: 'admin'
})
const store = useStore()
const router = useRouter()
const login = async () => {
  console.log(loginForm)
  const res = await permission.getMenu(loginForm)
  console.log(res)
  store.commit('setMenu', res.data.menu)
  // store.commit('addMenu', router)
  store.commit('setToken', res.token)
  router.push({
    name: 'home'
  })
}
</script>
<style lang="less" scoped>
.login-container {
  width: 350px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  border-radius: 15px;
  box-shadow: 0 0 25px #cacaca;
  margin: 180px auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  h3 {
    margin-bottom: 20px;
    color: #505450;
  }
  .el-input {
    width: 260px;
  }
  button {
    width: 60px;
    margin-bottom: 15px;
  }
}
</style>
